package demo1;

class Money implements Cloneable{
    public int money;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
public class Student implements Cloneable {
    private String name;
    private int score;
    public Money m = new Money();

    public Student(String name, int score) {
        this.name = name;
        this.score = score;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", score=" + score +
                ", m=" + m +
                '}';
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        Student temp = (Student) super.clone();
        //第一步：创建Student类的临时变量temp来接受clone后的student1
        temp.m = (Money) this.m.clone();
        //第二步：复制Money给temp的m
        return temp;
        //第三步：将temp给student2
    }
}
